package com.quyunshuo.module.home.fragment.video

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.quyunshuo.module.home.R
import com.quyunshuo.androidbaseframemvvm.network.bean.ArticleInfo

// RecyclerView Adapter
class SearchAdapter(private val data: List<ArticleInfo>) : RecyclerView.Adapter<SearchAdapter.ViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.rv_item_public_article, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.tvAuthor.text = data[position].author
        holder.tvTime.text = data[position].niceDate
        holder.tvContent.text = data[position].title
        holder.tvChapter.text = data[position].chapterName
    }

    override fun getItemCount() = data.size

    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val tvAuthor: TextView = itemView.findViewById(R.id.tvAuthor)
        val tvTime: TextView = itemView.findViewById(R.id.tvTime)
        val tvContent: TextView = itemView.findViewById(R.id.tvContent)
        val tvChapter: TextView = itemView.findViewById(R.id.tvChapter)

    }
}
